/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmRowStyle.h"
using namespace prs;

// TRuleFrmRowStyle ///////////////////////////////////////////////////////////

//
TRuleFrmRowStyle::TRuleFrmRowStyle(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleFrmStyleState &RStyleState
) 
:vParentNode(VParentNode)
,rStyleState(RStyleState)
{
  snt::TReturn         Return;
  snt::TFVoid          F;
  snt::text::TSequence T(Context);
  snt::text::TKeyword K(Context);
  snt::text::TNumber N(Context);
  prs::TFuncNewNodeIntoAttrOldChildren FNewNode;

  this->Name(GetClassName()).Local(vParentNode)
  | K.New("row") & FNewNode.New(VParentNode,TNodeFrmRowStyle()) & T.New("(") & A.New()
  ;
  
  A.Name(GetClassName() + "[A]")
  | T.New("row") & F.New(this,&TRuleFrmRowStyle::FNormal) & rStyleState.New() & A.New()
  
  | T.New("indent")   & F.New(this,&TRuleFrmRowStyle::FIndent)   & RIndent.New() /*rStyleState.New()*/ & A.New()
  | T.New("children") & F.New(this,&TRuleFrmRowStyle::FChildren) & rStyleState.New() & A.New()

  | T.New("captionNormal")   & F.New(this,&TRuleFrmRowStyle::FCaptionNormal)   & rStyleState.New() & A.New()
  | T.New("captionSelected") & F.New(this,&TRuleFrmRowStyle::FCaptionSelected) & rStyleState.New() & A.New()
  | T.New("captionFocused")  & F.New(this,&TRuleFrmRowStyle::FCaptionFocused)  & rStyleState.New() & A.New()

  | T.New(")") & Return.New()
  ;

  RIndent.Name(GetClassName() + "[RIndent]")
  | T.New("(") & AIndent.New()
  ;
  AIndent.Name(GetClassName() + "[AIndent]")
  | rStyleState.RuleInParts.New() & AIndent.New()
  | T.New("width") & T.New("=") & N.NewClosure(this,&TRuleFrmRowStyle::FIndentWidth) & AIndent.New()
  | T.New(")") & Return.New()
  ;
}

//
bool TRuleFrmRowStyle::FIndentWidth(snt::text::TNumber::TFuncClosureDoEntryParams &Params) 
{ 
  GetNode()->Style.Value.Indent.Width = Params.Number.GetValue();
  return true;
}

// TRuleFrmRowExpandStyle /////////////////////////////////////////////////////

//
TRuleFrmRowExpandStyle::TRuleFrmRowExpandStyle(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleFrmStyleState &RStyleState,
  TRuleFrmGeom &RFrmGeom
) 
:vParentNode(VParentNode)
,rStyleState(RStyleState)
,rGeometry(RFrmGeom)
{
  snt::TReturn         Return;
  snt::TFVoid          F;
  snt::text::TSequence T(Context);
  snt::text::TKeyword K(Context);
  prs::TFuncNewNodeIntoAttrOldChildren FNewNode;

  this->Name(GetClassName()).Local(vParentNode)
  | K.New("rowExpand") & FNewNode.New(VParentNode,TNodeFrmRowExpandStyle()) & T.New("(") & A.New()
  ;
  
  A.Name(GetClassName() + "[A]")
  | F.New(this,&TRuleFrmRowExpandStyle::FSetGeometry) & RFrmGeom.New() & A.New()
  
  | T.New("noneChildren") & F.New(this,&TRuleFrmRowExpandStyle::FNoneChildren) & rStyleState.New() & A.New()
  | T.New("collapse")     & F.New(this,&TRuleFrmRowExpandStyle::FCollapse)     & rStyleState.New() & A.New()
  | T.New("expand")       & F.New(this,&TRuleFrmRowExpandStyle::FExpand)       & rStyleState.New() & A.New()

  | T.New(")") & Return.New()
  ;
}
